<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <meta http-equiv="X-UA-Compatible" content="ie=edge" />
  <title>大事件-后台登录页</title>
  <link rel="stylesheet" type="text/css" href="css/reset.css" />
  <link rel="stylesheet" type="text/css" href="css/iconfont.css" />
  <link rel="stylesheet" type="text/css" href="css/main.css" />
  <!-- 引入bootstrap的css文件 -->
  <link rel="stylesheet" href="./libs/bootstrap/css/bootstrap.min.css" />
</head>

<body>
  <div class="main_wrap">
    <div class="header">
      <a href="#" class="logo"><img src="images/logo.png" alt="" /></a>
      <div class="copyright">
        CopyRight © 2019 深圳百秀信息技术股份有限公司<br />All Rights Reserved
      </div>
    </div>

    <div class="login_form_con">
      <div class="login_title"></div>
      <form class="login_form">
        <i class="iconfont icon-user"></i>
        <i class="iconfont icon-key"></i>
        <input type="text" class="input_txt" placeholder="邮箱/手机号" />
        <input type="password" class="input_pass" placeholder="密码" />
        <input type="submit" class="input_sub" value="登 录" />
      </form>
    </div>
  </div>

  <!-- 弹出框 -->
  <!-- Modal弹出框 -->
  <div class="modal fade" id="modelId" tabindex="-1" role="dialog" aria-labelledby="modelTitleId" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">提示</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <div class="container-fluid">
                    新增成功，稍后为您自动跳转
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">确认</button>
            </div>
        </div>
    </div>
</div>
</body>
<!-- 引入jp文件 -->
<script src="./libs/jquery-1.12.4.min.js"></script>
<script src="./libs/bootstrap/js/bootstrap.min.js"></script>
<script src="./libs/http.js"></script>
<script>
$(function(){
  $('.input_sub').on('click',function(e){
       //按钮是一个submit按钮，有一个默认提交行为，我们不需要，要阻止
       e.preventDefault();
    let username = $('.input_txt').val().trim();
    let password = $('.input_pass').val().trim();
    // 验证非空
    if(username == '' || password == ''){
        $('.container-fluid').text('用户名或者密码都不可以为空');
        $('#modelId').modal();
        return;
    };
    $.ajax({
      url : BigNew.user_login,
      type : 'post',
      data : {
        username : username,
        password : password
      },
      success : function(res){
        $('.container-fluid').text(res.msg);
        $('#modelId').modal();
       if(res.code === 200){
       localStorage.setItem('token',res.token);
         $('#modelId').on('hidden.bs.modal', function (e) {
          // 该事件表示弹出框隐藏了再执行的代码
         location.href = './index.html';
            })
       }
      }
    })
  })
})


</script>
</html>